//
//  PhotoLibrary.swift
//  permission
//
//  Created by Mr.wang on 2018/12/10.
//  Copyright © 2018 Mr.wang. All rights reserved.
//

import Photos

struct PhotoLibrary: Permission {
    
    static var status: PermissionStatus {
        let status = PHPhotoLibrary.authorizationStatus()
        
        switch status {
        case .authorized:          return .authorized
        case .denied, .restricted: return .denied
        case .notDetermined:       return .notDetermined
        @unknown default:          return .disabled
        }
    }
    
    static func requestPermission(_ closure: @escaping (PermissionStatus) -> ()) {
        PermissionType.photoLibrary.checkInfoPlist()
        PHPhotoLibrary.requestAuthorization { _ in
            closure(status)
        }
    }
}
